package com.fish.web.passport;

import java.util.ArrayList;
import java.util.List;

import com.fish.common.constant.QueryPage;
import com.fish.common.web.BaseAction;
import com.fish.passport.po.PassProvider;
import com.fish.service.passport.PassProviderService;

/**
 * 设备管理
 * 
 * @author clj
 * 
 */
public class ProviderAction extends BaseAction {
	private static final long serialVersionUID = -7845440946951357463L;
	private PassProvider provider = new PassProvider();
	private PassProviderService passProviderService;
	private List<PassProvider> providerList = new ArrayList<PassProvider>();
	private QueryPage queryPage = new QueryPage();

	public String edit() {
		if (this.provider.getProviderId() == null) {
			this.passProviderService.addPassProvider(provider);
		} else {
			this.passProviderService.updatePassProvider(provider);
		}
		return SUCCESS;
	}

	public String delete() {
		if (this.provider.getProviderId()!=null) {
			this.passProviderService.deletePassProvider(provider.getProviderId());
		}
		return providerList();
	}

	public String goToEdit() {
		if (this.provider != null) {
			this.provider = this.passProviderService.getPassProviderById(this.provider.getProviderId());
		}
		return SUCCESS;
	}

	public String providerList() {
		Long count = passProviderService.queryPassProviderCountByObject(provider);
		if(count > 0){
			queryPage = new QueryPage(count, 2, queryPage.getCurPage());
		}		
		providerList = passProviderService.queryPassProviderByObject(provider,queryPage);
		return SUCCESS;
	}

	public PassProvider getProvider() {
		return provider;
	}

	public void setProvider(PassProvider provider) {
		this.provider = provider;
	}

	public PassProviderService getPassProviderService() {
		return passProviderService;
	}

	public void setPassProviderService(PassProviderService passProviderService) {
		this.passProviderService = passProviderService;
	}

	public List<PassProvider> getProviderList() {
		return providerList;
	}

	public void setProviderList(List<PassProvider> providerList) {
		this.providerList = providerList;
	}

	public QueryPage getQueryPage() {
		return queryPage;
	}

	public void setQueryPage(QueryPage queryPage) {
		this.queryPage = queryPage;
	}
	
}
